﻿var popupStatus = 0;

//Carga el Popup de Rechazo
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		var bp = top.frames["sommaire"].document.getElementById('backgroundPopup');
		var pr = top.frames["sommaire"].document.getElementById('popupReject');
		$(bp).css({
			"opacity": "0.7"
		});
		$(bp).fadeIn("slow");
		$(pr).fadeIn("slow");
		popupStatus = 1;
	}
}

//Desaparecer Popup Rechazo
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		var taTextArea = document.getElementById("rejectCommentsTA");
		$("#backgroundPopup").fadeOut("slow");
		$("#popupReject").fadeOut("slow");
		popupStatus = 0;
		//taTextArea.value = "";
	}
}

//Centrar Popup Rechazo
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupReject").height();
	var popupWidth = $("#popupReject").width();
	//centering
	$("#popupReject").css({
		"position": "absolute",
		"top": windowHeight-popupHeight-100,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

//CONTROLLING EVENTS IN jQuery

function print(msje, value)
{
	alert(msge + ": " + value);
}

$(function() {
    var offset = $("#popupSave").offset();    
    var topPadding = 15;
    $(window).scroll(function() {
        if ($("#popupSave").height() < $(window).height() && offset != null && $(window).scrollTop() > offset.top) {
//        	alert($(window).scrollTop() - offset.top + topPadding);        	
            $("#popupSave").stop().animate({
                marginTop: $(window).height()/2 - $("#popupSave").height()/2 + $(window).scrollTop()
            });
        } else {
            $("#popupSave").stop().animate({
                marginTop: $(window).height()/2 - $("#popupSave").height()/2
            });
        };
    });
});

$(document).ready(function(){
	
	$("#btnReject_button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupRejectClose").click(function(){
		disablePopup();
	});
	$("#buttonRejectPopup").click(function(){
		disablePopup();
	});	
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	$("#buttonPopupSave").click(function(){
		disableSavePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});